# @Time    : 2021/9/26 2:27
# @Author  : tzhhone
# @File    : html_downloader.py
# @Explain : html下载器
import os

from tzhhone_reptile.html_parser import HtmlParser
from tzhhone_useragent import UserAgent
from tzhhone_bsc import Bsc
from tzhhone_reptile.log import Log
import yaml

ua = UserAgent()
yaml_path = os.path.join(os.getcwd(), "config.yaml")
file = open(yaml_path, 'r', encoding='utf-8')
data = yaml.load(file, Loader=yaml.FullLoader)
file.close()


class HtmlDownLoader(Log):
    # last_id = 0
    proxies = data["requests"]["proxies"]

    def __init__(self, token):
        self.token = token
        self.bsc = None

    def start(self):
        """
        启动html下载器，读取bsc币种首页
        :return:Bsc
        """
        self.bsc = Bsc(ua.get(), self.token, HtmlDownLoader.proxies)
        return self.bsc

    def get_bsc(self):
        """
        返回bsc对象
        :return: Bsc
        """
        return self.bsc

    def get_response(self):
        """
        返回Response对象
        :return:Response
        """
        return self.bsc.html
